/*
 * main.go
 * 
 * Copyright 2013 Mykola Dvornik <mykola.dvornik@gmail.com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * 
 */

package main

import (
	"flag"
	"log"
	"code.google.com/p/semargl4/io"
	plog "code.google.com/p/semargl4/logger"
	mm "code.google.com/p/semargl4/mmanager"
	"strings"
	"time"
)

type module struct {
	ContDir int64 // -1 - the module performs local stuff
	Comp    int64 // component of the data to work with
	Run     func()
	Params  interface{}
}

//~ name -> opcodes
var (
	modeOpcodeMap = map[string]uint{"TXYZ": 0,
		"XYZ": 1,
		"TXY": 2,
		"TYZ": 3,
		"TXZ": 4,
		"XY":  5,
		"YZ":  6,
		"XZ":  7,
		"T":   8,
		"TX":  9,
		"TY":  10,
		"TZ":  11,
		"X":   12,
		"Y":   13,
		"Z":   14,
	}

	formatOpcodeMap = map[string]uint{"AP": 0,
		"XY": 1,
	}
)

var (
	modeFuncMap = map[uint]func(){1: mXYZ}

	formatFuncMap = map[uint]func(){0: fAP,
		1: fXY}
)

var (
	flag_silent   = flag.Bool("s", false, "keep it silent")
	flag_mode     = flag.String("mode", "XYZ", "what should semargl do")
	flag_format   = flag.String("format", "AP", "what should semargl output")
	flag_basename = flag.String("basename", "m", "the base name for output files")
)

func fAP() {
	log.Println("Sisi")
	return
}

func fXY() {
}

func mXYZ() {

}

func main() {
	go plog.Start()
	flag.Parse()
	if !(*flag_silent) {
		plog.Print("semargl4 by Mykola Dvornik (c) 2007-2013 and Volodymyr Kruglyak (c) 2007-2012")
	}
	// process command que
	*flag_mode = strings.ToUpper(*flag_mode)
	// go does not have sort method for a single string!

	if flag.NArg() == 0 {
		plog.Print("nothing to do.")
		return
	}

	io.CheckDataExist(flag.Args())
	io.ReadDumpHeader(flag.Args()[0])
	plog.Print(io.RefHeader.String())

	mmngr := mm.NewMemoryManager(flag.Args(), []int64{int64(io.RefHeader.MeshSize[0]), int64(io.RefHeader.MeshSize[1]), int64(io.RefHeader.MeshSize[2])})
	go mmngr.Run()
	time.Sleep(1.0 * time.Second)
	mmngr.Stop()
	time.Sleep(1.0 * time.Second)
}
